<template>
  <div class="SiteDataCount-content">
    <Row :gutter="4">
      <Col span="3">
        <Input placeholder="采集站编号" v-model="queryObj.siteCode"/>
      </Col>
      <Col span="2">
        <Input placeholder="IP" v-model="queryObj.ip"/>
      </Col>
      <Col span="4">
        <DatePicker v-model="queryObj.reportDate" type="date" format="yyyy-MM-dd" placeholder="请选择统计日期" style="width: 100%"></DatePicker>
      </Col>
      <Col span="2">
        <Button type="primary" @click="handleSearch()">查询</Button>
      </Col>
    </Row>
    <div class="panel-count">
      共 <span class="count-number">{{this.total.toLocaleString()}}</span> 条数据({{this.spendTime}} 秒)
    </div>
    <Card>
      <tables :loading="loading" stripe :row-class-name="rowClassName" ref="tables" v-model="tableData" :columns="columns"/>
      <Page class="panel-page" :total="total" :current="page" :page-size="size" @on-change="changePage" show-elevator />
    </Card>
  </div>
</template>

<script>
import Tables from '_c/tables'
import { apiSearch } from '@/api/siteDataCount'
import {apiResult} from "@/libs/util";
import {apiLog} from "@/api/SiteApiTest";
export default {
  name: 'SiteDataCount',
  components: {
    Tables
  },
  data () {
    return {
      columns: [
        { title: '采集站编号', key: 'siteCode', sortable: false },
        { title: 'IP', key: 'ip', sortable: false },
        { title: '统计时间', key: 'reportDate', sortable: false },
        { title: '统计数', key: 'dataCount', sortable: false },
        { title: '上传时间', key: 'createTime', sortable: false }
      ],
      tableData: [],
      page: 1,
      size: 10,
      total: 0,
      spendTime: 0,
      queryObj: {
        siteCode: '',
        ip: '',
        reportDate: ''
      },
      loading: false
    }
  },
  methods: {
    // 获取数据
    getData () {
      this.loading = true
      const param = JSON.stringify(this.queryObj)
      // console.log(param)
      apiSearch(this.page, param).then(res => {
          apiResult(res.data,false,result=>{
            this.total = result.data.total
            this.page = result.data.page
            this.spendTime = result.data.spendTime
            this.tableData = result.data.content
            this.loading = false
          })
        // console.log(res.data)
        /*if (code === 0) {
          this.total = res.data.data.total
          this.page = res.data.data.page
          this.spendTime = res.data.data.spendTime
          this.tableData = res.data.data.content
          this.loading = false
        } else {
          this.$Message.error(res.data.msg)
        }*/
      })
    },
    // 点击页码
    changePage (page) {
      this.page = page
      this.getData()
    },
    handleSearch () {
      this.page = 1
      this.getData()
    }
  },
  mounted () {
    this.page = 1
    this.getData()
  }
}
</script>

<style lang="less">
  @import "./SiteDataCount";
</style>
